package goroutine

import "fmt"

func sum(c chan int, nums ...int) {
	sum := 0
	for _, number := range nums {
		sum += number
	}
	c <- sum
}

func ChannelDemo() {
	list := []int{1, 2, 3, 4, 5, 6}
	channel := make(chan int)
	go sum(channel, list[:2]...)
	go sum(channel, list[3:]...)

	x, y := <-channel, <-channel
	fmt.Println("x + y =", x+y)
}
